package main

import (
	"fmt"
	"strings"
)

func main() {
	s := "hello                "
	fmt.Println(countSegments(s))
}

//#link: https://leetcode-cn.com/problems/number-of-segments-in-a-string/
func countSegments(s string) int {
	strArray := strings.Split(s, " ")
	result := 0
	for i := 0; i < len(strArray); i++ {
		if strings.Trim(strArray[i], " ") != "" {
			result++
		}
	}
	return result
}
